package com.doubao.strategy.tplStrategy;

import com.doubao.config.AppConstant;
import com.doubao.contoller.UserContoller;
import com.doubao.protocol.Msg;
import com.doubao.protocol.TextMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * description:TplStrategyContext
 * <p>
 * author:sult
 * time: 2018/11/3 15:33
 **/
public class TplStrategyContext {

    private static final Logger log = LoggerFactory.getLogger(TplStrategyContext.class);

    public static Boolean sendTplMsg(TextMsg msg){
        TplStrategy tplStrategy=null;
        switch (msg.getToUserType()){
            case AppConstant.USER_TYPE_CLIENT:
                tplStrategy=new ClientTplStrategy();
                break;
            case AppConstant.USER_TYPE_AGENT:
                tplStrategy=new AgentTplStrategy();
                break;
        }
        if(tplStrategy!=null){
            try {
                return tplStrategy.sendTplMsg(msg);
            } catch (Exception e) {
                log.error("模板消息发送失败了！！错误信息：{}",e);
                e.printStackTrace();
                return false;
            }
        }
        log.error("请检查传入的toType是否有误");
        return false;
    }

}
